package com.mpp.common.util;

import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.io.IOException;
import java.nio.file.Files;

/**
 * @ClassName : FileUstils  //类名
 * @Description : 附件上传  //描述
 * @Author : 易嵘  //作者
 * @Date: 2022-08-19 15:10  //时间
 */
@RestController
@RequestMapping("/file")
public class FileUstils {


        @ResponseBody
        @RequestMapping(value = "/upload", method = RequestMethod.POST, consumes = "multipart/form-data")
        public String upload(@RequestPart MultipartFile file) throws IOException {
            String fileName = file.getOriginalFilename();
            String filePath = fileName;

            File dest = new File(filePath);
            Files.copy(file.getInputStream(), dest.toPath());
            return "Upload file success : " + dest.getAbsolutePath();
    }
}
